#pragma once
#include "Common/ServerDefine.h"
#include "Common/NetPack/NetPack.h"
#include "base/core/script.h"

// protobuf error throw exception, don't abort
#ifndef PROTOBUF_USE_EXCEPTIONS
#define PROTOBUF_USE_EXCEPTIONS 1
#endif // !PROTOBUF_USE_EXCEPTIONS


/* return : > sizeof(NetPack) complete pack
**          = 0               not complete pack
**          < 0               illegal pack lenght, need close session
*/
int  SubNetPack(const char* data, int len, int maxLen, int maxCmd);
int  SubClientNetPack(const char* data, int len);
int  SubServerNetPack(const char* data, int len);
//Time::UnixSec()
bool ConnectService(Net* net, ServiceConnect* connect, time_t timeInSecond, OnConnectFunc callback, void* context);

bool CloseServerConnection(Net* net, ServiceConnect *connect);
bool SerializeProtobufToArray(const ProtoBufBase* pb, void* data, int size);

class LuaParser;
struct MYSQL_SERVER_PARAM;
bool LoadServiceConnectConfig(LuaParser& parser, const char *configName, ServiceConnect *connect);
bool LoadConfigConnect2Service(LuaRef& parserRef, const char *configName, ServiceConnect *connect);
bool LoadConfigConnectMap2Service(LuaRef& parserRef, const char *configName, CONNECT_MAP& conMap);
bool LoadMySQLParam(LuaParser& parser, const char* configName, MYSQL_SERVER_PARAM* param);

bool LoadMySQLParam(LuaRef& parser, MYSQL_SERVER_PARAM* param);
bool LoadRedisParam(LuaRef& parser, REDIS_SERVER_PARAM* param);

ScriptPack* GenerateScriptPack(LuaScript* sc, int stackIndex);
